<?php
declare(strict_types=1);

namespace app\service;

use app\model\Merchant;
use think\facade\Db;

class MerchantService
{
    /**
     * 创建商家
     */
    public function create(array $data): Merchant
    {
        Db::startTrans();
        try {
            // 创建商家
            $merchant = Merchant::create($data);
            
            // 初始化商家默认消息模板
            $migration = new \database\migrations\InitMessageTemplates();
            $migration->createMerchantDefaultTemplates($merchant->id);
            
            Db::commit();
            return $merchant;
            
        } catch (\Exception $e) {
            Db::rollback();
            throw $e;
        }
    }
} 